import {
    createRouter,
    createWebHashHistory
} from 'vue-router'
import Layout from '@/views/layout/Layout.vue'
import {adminRouter} from './modules/admin'
import {homeRouter} from "@/router/modules/home";
import {dataHubRouter} from "@/router/modules/dataHub";
import {messageRouter} from "@/router/modules/message";
import {assessmentRouter} from "@/router/modules/assessment";
import {userProfileRouter} from "@/router/modules/userProfile";
import {parentRouter} from "@/router/modules/parent";


export const routes = [
    // 初始化重定向
    {
        path: '',
        name: 'layout',
        component: Layout,
        redirect: '/home',
    },
    // 登录
    {
        path: '/login:redirect?',
        name: 'login',
        component: () => import('@/views/Login'),
        meta: {noRequireAuth: true}
    },
    // 选择角色和校验账号
    {
        path: '/register',
        name: 'register',
        component: () => import('@/views/register/Register'),
        meta: {noRequireAuth: true}
    },
    // 注册 - 参数：角色，账号
    {
        path: '/register/from/:role?/:account?',
        name: 'registerForm',
        component: () => import('@/views/register/RegisterForm'),
        meta: {noRequireAuth: true}
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/error/404'),
        meta: {noRequireAuth: true}
    },
    {
        path: '/:pathMatch(.*)*',
        redirect: '/404'
    },
    parentRouter,
    homeRouter,
    adminRouter,
    dataHubRouter,
    messageRouter,
    assessmentRouter,
    userProfileRouter,
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})
// 当想要在非Vue的应用中调用时，通过$router
window.$router = router
export default router
